const mongoose = require('mongoose');
const pagination = require('mongoose-sex-page');

const { Article } = require('../../model/article')
const { Classify } = require('../../model/classify')
module.exports = async (req, res) => {
    // page 指定当前页
    // size 指定每页显示的数据条数,5
    // display 指定客户端要显示的页码数量
    // console.log(req.query);
    var page = req.params.page
    try {
        var data = await pagination(Classify).find().page(page).size(7).exec()
    } catch (err) {
        return res.send({
            data: null,
            meta: {
                status: 400,
                msg: '请求失败'
            }
        })
    }
    var arr = data.records
    for(let i in arr){
        var publish = await Article.find({class:arr[i]._id,status:true}).count()
        var save = await Article.find({class:arr[i]._id,status:false}).count()
        var total = publish+save
       var {_id,name} = arr[i]
       arr[i]={
           _id,name,publish,save,total
       }
    }
    data.records=arr
    res.send({
        data,
        meta: {
            status: 200,
            msg: '请求成功'
        }
    })
}